package com.jt.controller;

import com.jt.pojo.ItemCatParam;
import com.jt.service.ItemCatParamService;
import com.jt.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 刘昱江
 * 时间 2021/3/31
 */
@RestController
@RequestMapping("/itemCatParam")
@CrossOrigin
public class ItemCatParamController {

    @Autowired
    private ItemCatParamService itemCatParamService;

    /**
     * 根据商品分类id和类型查询分类参数
     * URL地址: http://localhost:8091/itemCatParam/findItemCatParamListByType?paramType=2&itemCatId=3
     * 参数:  type=2/itemCatId=3
     * 返回值: SysResult对象
     */
    @GetMapping("/findItemCatParamListByType")
    public SysResult findItemCatParamListByType(ItemCatParam itemCatParam){

        List<ItemCatParam> paramList = itemCatParamService.findItemCatParamListByType(itemCatParam);
        return SysResult.success(paramList);
    }

    /**
     * 实现商品分类参数更新
     * URL:/itemCatParam/updateItemCatParamVals
     * 参数: itemCatId.paramVals
     * 返回值: sysResult对象
     */
    @PostMapping("/updateItemCatParamVals")
    public SysResult updateItemCatParamParamVals(ItemCatParam itemCatParam){

        itemCatParamService.updateItemCatParam(itemCatParam);
        return SysResult.success();
    }

    /**
     * 新增商品分类参数
     * URL: http://localhost:8091/itemCatParam/addItemCatParam
     * 参数: form参数
     * 返回值: SysResult对象
     */
    @PostMapping("addItemCatParam")
    public SysResult addItemCatParam(@RequestBody ItemCatParam itemCatParam){

        itemCatParamService.addItemCatParam(itemCatParam);
        return SysResult.success();
    }

    /**
     * 新增商品分类参数
     * URL: http://localhost:8091/itemCatParam/updateItemCatParam
     * 参数: form参数
     * 返回值: SysResult对象
     */
    @PutMapping("updateItemCatParam")
    public SysResult updateItemCatParam(@RequestBody ItemCatParam itemCatParam){

        itemCatParamService.updateItemCatParam(itemCatParam);
        return SysResult.success();
    }

    /**
     * 删除商品分类参数
     * URL: http://localhost:8091/itemCatParam/deleteItemCatParamById
     * 参数: form参数
     * 返回值: SysResult对象
     */
    @DeleteMapping("deleteItemCatParamById")
    public SysResult deleteItemCatParam(Integer paramId){

        itemCatParamService.deleteItemCatParamById(paramId);
        return SysResult.success();
    }
}
